const update = {


    // 请求上传图片
    getUserInforText: function (file, callback) {
        this.public('/home/upload/add', {
            file: file
        }, callback);
    },


    //公共请求的function
    public: function (methods, data, success, error) {
        let xhr = new XMLHttpRequest();
        let formData = new FormData();
        for (let key in data) {
            formData.append(key, data[key]);
        }
        formData.append("authkey", localStorage.getItem("authkey"));
        formData.append("sessionid", localStorage.getItem("sessionid"));

        xhr.open("post", process.env.API_URL + methods);
        xhr.send(formData);
        xhr.onreadystatechange = function () {
            if (xhr.status === 200) {
                if (xhr.readyState === 4) {
                    let responseData = JSON.parse(xhr.responseText);
                    if (success) success(responseData);
                }
            } else {
                if (errorHandler) {
                    let responseData = JSON.parse(xhr.responseText);
                    if (error) error(responseData);
                } else {
                    alert("请求失败！" + xhr.responseText);
                }
            }
        };
    }
}